package com.cysion.study.ui.fragment

import com.cysion.study.ktbox.base.BaseFragment
import com.cysion.study.ktbox.net.BaseResponseRx
import com.cysion.study.ktbox.net.ErrorHandler
import com.cysion.targetfun._subscribe
import com.cysion.study.uibox.dialog.Alert
import com.cysion.study.R
import com.cysion.study.customview.java.SimpleData
import com.cysion.study.helper.UserCache
import com.cysion.study.net.ApiClient
import com.cysion.study.widget.ShowToast


class NoSignInFragment : BaseFragment() {


    override fun getLayoutId(): Int = R.layout.fragment_nosignin


    val simpleDatas = arrayListOf<SimpleData.Students>()
    private var isSign = ""
    override fun initView() {
        isSign = arguments?.getString("isSign").toString()
        initRecyclerView()
        initVariable()
    }

    //初始化列表
    private fun initRecyclerView() {
//        recycler_view.isNestedScrollingEnabled = false
//        recycler_view.layoutManager = LinearLayoutManager(context)


        /*simpleAdaper.setOnItemClicks {position, flag ->
            //flag 1 签到
            sendSign(flag.sid)
        }*/
    }

    //签到/点名
    private fun sendSign(sid: String) {
        Alert.loading(context)
        //点名类型 0.托管课程 1.市集课程
        ApiClient.api.rollCall(UserCache.token, "", sid, "0")
            .compose(BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    Alert.close()
                    ShowToast("签到成功")
                    getDataList()
                }
                _onError {
                    Alert.close()
                    ShowToast(ErrorHandler.handle(it).errorMsg)
                }
            }
    }

    override fun initData() {
        super.initData()
        getDataList()
    }

    var dataBean: SimpleData? = null

    private fun getDataList() {
        Alert.loading(context)
        //isSign 是否签到 -1.全部 0.已签到 1.未签到
        ApiClient.api.getOwnClasses(UserCache.token,isSign)
            .compose(BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    Alert.close()
                    /*if (it.students.size == 0) {
                        multiView.showEmpty()
                    } else {
                        dataBean = it
                        simpleAdaper.setDatas(it.students)
                        simpleAdaper.notifyDataSetChanged()
                        multiView.showContent()
                    }*/
                }
                _onError {
                    Alert.close()
                    ShowToast(ErrorHandler.handle(it).errorMsg)
                }
            }
    }

    private fun initVariable() {

        /*for (i in 0..25) {
            CLog.i(i.toString())
            simpleDatas.add(SimpleData(Constants.TYPE_HEADER, (i + 65).toString()))
//            simpleDatas.add(SimpleData(Constants.TYPE_HEADER, side_bar.alpha))
//            simpleDatas.add(SimpleData(Constants.TYPE_HEADER, "头部"))
            for (j in 0..4) {
                simpleDatas.add(SimpleData(Constants.TYPE_DATA, (i + 65).toString() + " Hello World " + j))
            }
        }*/

    }

    override fun closeMvp() {
    }

}
